package com.lidx.back.statistics.rest.app;

import org.springframework.util.StringUtils;

import com.lidx.back.statistics.commons.Constants;
import com.lidx.back.statistics.entity.ClientInfo;
import com.lidx.back.statistics.rest.RestRequest;
import com.lidx.back.statistics.rest.VersionBean;

public class AppInitRequestCheck {

	public ClientInfo checkInput(RestRequest request) throws Exception{
		if(StringUtils.isEmpty(request.getDeviceId()) || StringUtils.isEmpty(request.getSex())){
			throw new Exception("deviceId和sex不能为空！");
		}
		ClientInfo clientInfo = new ClientInfo();
		clientInfo.setDeviceId(request.getDeviceId());
		String sex = request.getSex();
		if(!Constants.PERSON_SEX_FEMALE.equals(sex) && !Constants.PERSON_SEX_MALE.equals(sex)){
			throw new Exception("性别选择只能为男或者女");
		}
		clientInfo.setSex(request.getSex());
		VersionBean version = request.getVersion();
		if(null != version){
			if(!StringUtils.isEmpty(version.getVersionNumber())){
				clientInfo.setVersionNum(version.getVersionNumber());
			}
			if(!StringUtils.isEmpty(version.getVersionType())){
				clientInfo.setVersionType(version.getVersionType());
			}
		}
		return clientInfo;
	}
}
